<%@ page language="java" pageEncoding="UTF-8" buffer="16kb"%>
<%@ include file="/base.jsp"%>
<%@ include file="/module/taglibs.jsp"%>
<%@ include file="/module/nocache.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>新增科研信息</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<%@ include file="/module/js.jsp"%>
<%@ include file="/module/orderField.jsp"%>
	<script type="text/javascript" src="${basePath}/js/jquery.Huploadify.js"></script>
	<link href="${basePath}/css/Huploadify.css" rel="stylesheet">
	<style>
	table label.error {
		margin-left: 5px;
		width: auto;
		display: inline;
		color: red;
	}
	.textat {text-align: center;}
	</style>
	<script type="text/javascript">
        //图片上传
        var file_path = "prefix";
        var file_path_one = null;
        var fileMap = new Array();
        $(function(){
            var up = $('#uploadadd').Huploadify({
                auto:false,
                fileTypeExts:'*.*',
                multi:true,
                formData:{key:123456,key2:'vvvv'},
                fileSizeLimit:99999999999,
                showUploadedPercent:true,
                showUploadedSize:true,
                removeTimeout:9999999,
                uploader : '${basePath}/scientificNotice/source_upload',
                onUploadStart:function(file){
                    console.log(file.name+'开始上传');
                },
                onInit:function(obj){
                    console.log('初始化');
                    console.log(obj);
                },
                onUploadComplete:function(file,data){
                    debugger;
                    var fi = $.parseJSON(data);
                    //文件名称
                    var filename = fi.fileName;
                    //生成后的文件名
                    var sysFilepath = fi.sysfilepath;
                    //文件路径
                    var filepath = fi.filePath;
                    file_path_one = filename + "," + filepath;
                    file_path = file_path+"|"+filepath;
                    up.filePath=file_path_one;
                    //保存到集合
                    fileMap[file.index]=new Array(file_path_one);
                },
                onCancel:function(file){
                    console.log(file.name+'删除成功');
                },
                onClearQueue:function(queueItemCount){
                    console.log('有'+queueItemCount+'个文件被删除了');
                },
                onDestroy:function(){
                    console.log('destroyed!');
                },
                onSelect:function(file){
                    console.log(file.name+'加入上传队列');
                },
                onQueueComplete:function(queueData){
                    console.log('队列中的文件全部上传完成',queueData);
                }
            });
        });

        //删除图片
        function deletefile(id){
            var url = "${basePath}/scientificNotice/deletefile";
            $.ajax({
                type : "POST",
                url : url,
                dataType:"json",
                data:{
                    filepath : id
                },
                success : function(data) {
                    if(data.success == "0000"){
                        alert("删除数据成功！");
                        var file_name = id.split(",")[0];
                        $("#"+file_name+"_hr").parent().parent().remove();
                    }else{
                        alert("未写入数据库的文件没有删除！请联系管理员！");
                    }
                }
            })
        }
        function show1(_this){
       		var val = $(_this).val();
       	 	if(val == '1') {
     	      	$("#view").hide();
     	    }else if(val == '2') {
     	      	$("#view").show();
     	    }
        }
        
	</script>
</head>
<body>
	<form action="#" name="Form" id="Form" method="post">
	<input type="hidden" name="id" id="id" value="" />
		<table cellpadding="0" cellspacing="0" border="0" class="table-border" width="95%">
			<tr>
				<td class="table-header" colspan="4">科研信息</td>
			</tr>
			<tr>
				<td class="table-titleTD" style="width: 15%"><font
						style="color: red;">*</font>标题：</td>
				<td class="table-contentTD" colspan="3" style="width: auto;">
					<input id="subject" name="subject"  placeholder="标题"  autocomplete="off" maxlength="100" style="width: 80%" class="inputText required" /></td>
			</tr>
			<tr>
				<td class="table-titleTD" style="width: 15%"><font
						style="color: red;">*</font>类别：</td>
				<td class="table-contentTD" style="width: 35%">
					<input id="xxlb_1" type="radio" name="xxlb" value="1" onclick="javascript:show1(this);" checked/>&nbsp;<label for="xxlb_1">通知公告</label>
					<input id="xxlb_2" type="radio" name="xxlb" onclick="javascript:show1(this);" value="2"/>&nbsp;<label for="xxlb_2">文件传阅</label>
				</td>
				<td class="table-titleTD" style="width: 15%">来源：</td>
				<td class="table-contentTD" style="width: 35%">
					<input id="xxly" name="xxly" placeholder="来源" autocomplete="off" maxlength="100" class="inputText" />
				</td>
			</tr>
			<tr>
				<td class="table-titleTD" style="width: 15%">发表单位：</td>
				<td class="table-contentTD" style="width: 35%">
					<input id="fbdw" name="fbdw" placeholder="发表单位" autocomplete="off" maxlength="100" class="inputText" />
				</td>
				<td class="table-titleTD" style="width: 15%">发表日期：</td>
				<td class="table-contentTD" style="width: 35%">
					<input name="fbrq" id="fbrq" placeholder="发表日期"   autocomplete="off"
						   class="Wdate inputText2" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"/></td>
			</tr>
			<tr>
				<td class="table-titleTD" style="width: 15%">创建人：</td>
				<td class="table-contentTD" style="width: 35%">
					<input type="hidden" id="creatorName" name="creatorName" value="${creatorName}" />
					${entity.creatorName}
				</td>
				<td class="table-titleTD" style="width: 15%">创建日期：</td>
				<td class="table-contentTD" style="width: 35%">
					${entity.createTime}
				</td>
			</tr>
			<tr id="view" style="display: none;"> <!-- style="display: none;" -->
				<td class="table-titleTD" style="width: 15%"><font
						style="color: red;">*</font>传阅给：</td>
				<td class="table-contentTD" colspan="3" style="width: auto;">
                     <input
					type="text" id="name" name="name" value="" maxlength="100"  readonly="readonly" placeholder="传阅人" class="inputText"/>&nbsp&nbsp;
					<input type="button" id="optionBtn" value="选择" class="inputButton" 
					onclick="javascript:showdiv2();" placeholder="请选择传阅人"/>
				</td>
			</tr>
			<tr>
				<td class="table-titleTD" style="width: 15%">附件：</td>
				<td class="table-contentTD" colspan="3" style="width: auto;">
					<table>
						<tr>
							<td colspan="2">
								<div id="uploadadd"></div>
							</td>
						</tr>
						<c:forEach items="${dataList}" var="datalist" varStatus="index">
							<tr>
								<td>
									[文件] ${datalist.fileName}
								</td>
								<td>
									<a href="${basePath}/DownLoadFileServlet?filename=${datalist.fileName}&filepath=${datalist.filePath}">下载</a>
									<button id="${datalist.gid}_hr" type="button"  onclick="deleteByPK('${datalist.gid}');">删除</button>
								</td>
							</tr>
						</c:forEach>
					</table>
				</td>
			</tr>
			<tr>
				<td class="table-titleTD">内容：</td>
				<td class="table-contentTD" colspan="3">
					<textarea rows="5" cols="50" name="contents" id="contents" maxlength="500" ></textarea>
				</td>
			</tr>
		</table>
	</form>
		<div id="div2" style="display: none;">
			<table cellpadding="0" cellspacing="0" border="0"
				class="table-border">
				  <tr>
  	   <td style="clear:both; width: 45%">
  	  <input class="text" name="searchemp" ondblclick="javascript:filterSelectItems('sourseFromSelect2','fromSelect2','toSelect2',this.value);"  onkeyup="javascript:filterSelectItems('sourseFromSelect2','fromSelect2','fromSelect2',this.value);"/><font color="green">在此查找</font> <br/>
  	   <br/><label style="color:red;">未选中:</label><br/>
  	   <select name="fromSelect2" id="fromSelect2" multiple="multiple" style="width:400px; height: 300px;"
			ondblclick="moveField('fromSelect2','toSelect2');">
						<c:forEach items="${employees}" var="data">
							     <option value="${data.emid}">${data.xm}</option>
						</c:forEach>
		</select>
		 <select name="sourseFromSelect2" id="sourseFromSelect2" multiple="multiple" style="width:400px; height: 300px;display: none;"
				   ondblclick="moveField('fromSelect2','toSelect2');">
			 <c:forEach items="${employees}" var="data">
				 <option value="${data.emid}">${data.xm}</option>
			 </c:forEach>
		   </select>
  	    </td>
  	    <td align="center" style="width: 10%">
  	    <input type="button"  onclick="moveAllField('fromSelect2','toSelect2');" style="width: 50px;" value=">>" />
		<br>
		 <br/>
		<input type="button" 
			onclick="moveField('fromSelect2','toSelect2');"
			style="width: 50px;" value=">" />
	   <br/>
	    <br/>
		<input type="button"   style="width: 50px;" value="&lt" onclick="moveField('toSelect2','fromSelect2');"/><br/> <br/>
     	<input type="button" style="width: 50px;" onclick="moveAllField('toSelect2','fromSelect2');"  value="&lt&lt" />
     </td>
     <td style="width: 45%"><br/><label style="color:red;">已选中:</label><br/>
     <select name="toSelect2" id="toSelect2" multiple="multiple"  class="text"   style="width:400px;height: 300px;" ondblclick="moveField('toSelect2','fromSelect2');">
		</select>
     </td>
  	   </tr>
		</table>
  </div>
	<br />
	<table cellpadding="1" cellspacing="1" border="0" align="left">
	<c:if test="${_login_user_type==2}">
	<tr>
		<td>
		<kl:permission permisstionList="${permisstionList}"
               currentUser="${_login_console_user}"
               currentCatalogId="<%=CatalogUtils.getCatalogId(\"JKY_JKS_KYXX\")%>" key="add">
		<input type="button" id="btnSave" class="inputButton textat"  autocomplete="off" value="保存" />
		</kl:permission>
		</td>
		<td>
		<kl:permission permisstionList="${permisstionList}"
               currentUser="${_login_console_user}"
               currentCatalogId="<%=CatalogUtils.getCatalogId(\"JKY_JKS_KYXX\")%>" key="add">
		<input type="button" id="btnSaveContinue" class="inputButton textat" autocomplete="off" value="保存并新增" />
		</kl:permission>
		</td>
		<td><input type="button" id="Cancel" class="inputButton textat" autocomplete="off" value="取消" /></td>
		<td><input type="button" id="returnBut" class="inputButton textat" autocomplete="off" value="返回"/></td>
	</tr>
	</c:if>
	</table>
	<script>
		$(document).ready(function() {
			$("#div2").dialog({
				width : 'auto',
				height : 'auto',
				bgiframe : true,
				modal : true,
				draggable : true,
				resizable : true,
				title : '选择传阅人',
				autoOpen : false,
			    buttons : {
			    '取消' : function() {
			    	$(this).dialog('close');
				},
				'确定' : function() {
				 /*   if($("#toSelect2").val()==null||$("#toSelect2").val()==""){
					 alert("请选择一项");
					 return false;
				  }  */
				  var wyxm_id = $("#toSelect2 option").map(function(){
					     return $(this).val();
					 }).get().join(",")
				  var wyxm_name = $("#toSelect2 option").map(function(){
					     return $(this).text();
					 }).get().join(",")
					 /* alert(wyxm_name);
					 alert(wyxm_id); */
			      $("#name").val(wyxm_name);
				  $("#id").val(wyxm_id);
				  $(this).dialog('close');
				}
			  }
			});
			
			var _form=$("#Form").validate();
			$("#btnSave").click(function() {
				if(_form.form()){
					validataSave();
				}
			});
			$("#btnSaveContinue").click(function() {
				if(_form.form()){
				  	validataSaveContinue();
				}
			});
			function validataSave(){
			   	document.Form.action ="${basePath}/scientificNotice/save";
				document.Form.submit();
			}
			function validataSaveContinue(){
				document.Form.action ="${basePath}/scientificNotice/save?action=add";
				document.Form.submit();
			}
			$("#returnBut").click(function() {
			   	window.location.href='${basePath}/scientificNotice/index';
			});
			$("#Cancel").click(function() {
			   	window.location.href = "${basePath}/scientificNotice/addInInt";
			});
		});
	   	function showdiv2() {
			$('#div2').dialog('open');
		}
		//compareListValue(document.getElementById('mz'),'${student.mz}');
	</script>
</body>
</html>